package com.ruoyi.web.wx.controller;

import com.ruoyi.web.wx.entity.Rank;
import com.ruoyi.web.wx.entity.WxUser;
import com.ruoyi.web.wx.service.IEnvirBonusTotalService;
import com.ruoyi.web.wx.service.IWxUserService;
import com.ruoyi.web.wx.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("wx")
public class RankingController {
    @Autowired
    private IEnvirBonusTotalService envirBonusTotalService;
    @Autowired
    private IWxUserService wxUserService;
    @GetMapping("/rankingList")
    @ResponseBody
    public Rank List(Integer rankType, HttpServletRequest request){
    String token = request.getHeader("token");
    String openId = JwtUtil.getUserId(token);
    WxUser wxUser1 = wxUserService.selectWxUserByOpenId(openId);
    if (rankType==1){
        Rank rank= envirBonusTotalService.getRankList(wxUser1);
        return rank;
    }else {
        return null;
    }
    }
}
